package com.idanchuang.component.pushgateway;

import com.idanchuang.component.pushgateway.config.PushGatewayConfigBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yjy
 * @date 2020/4/10 13:59
 **/
@Configuration
public class ComponentPushgatewayAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "idanchuang.component.pushgateway")
    public PushGatewayConfigBean pushGatewayConfigBean() {
        return new PushGatewayConfigBean();
    }

    @Bean
    @ConditionalOnMissingBean(Pusher.class)
    public Pusher pushGateway(PushGatewayConfigBean pushGatewayConfigBean) {
        return new Pusher(pushGatewayConfigBean.getAddr());
    }

}
